{% load staticfiles %}
{% load node_tag %}
<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="renderer" content="webkit">

    <meta name="keywords" content="{% block keywords %}{% endblock %}">
    <meta name="description" content="{% block description %}{% endblock %}">

    <link href="{% static 'xadmin/css/bootstrap.min.css' %}" rel="stylesheet">
    <link href="{% static 'xadmin/font-awesome/css/font-awesome.css' %}" rel="stylesheet">
    <link href="{% static 'xadmin/css/plugins/iCheck/custom.css' %}" rel="stylesheet">
    <link href="{% static 'xadmin/css/animate.css' %}" rel="stylesheet">
    <link href="{% static 'xadmin/css/style.css' %}" rel="stylesheet">
    <link href="{% static 'xadmin/layui/css/layui.css' %}" rel="stylesheet">
    <link href="{% static 'xadmin/css/cms.css' %}" rel="stylesheet">
    <link href="{% static 'xadmin/layui/dtree/font/dtreefont.css' %}" rel="stylesheet" media="all">
    <link href="{% static 'xadmin/layui/dtree/dtree.css' %}" rel="stylesheet" media="all">
    <link href="{% static 'xadmin/css/plugins/toastr/toastr.min.css' %}" rel="stylesheet" media="all">
</head>

<body style="background-color: white;">
    <div class="container">
        <ul class="lanmu-info info dtree" id="lanmu-info" data-id="0" style="margin-top:20px;margin-left:20px;">
            {% for g in groups %}
                <li style="margin-bottom: 5px;">
                    <input type="checkbox" value="{{ g.id }}" class="i-checks" {% article_group_is_checked g.id checked_group %}> {{ g.name }}
                </li>
            {% endfor %}
        </ul>
        <div class="row" style="margin-top:20px;">
            <div style="width: 500px;min-height: 500px;margin:0 auto;">
                <button type="button" class="btn btn-sm btn-primary" onclick="article_add_group()">提交</button>
                <button type="button" style="margin-left: 20px;" class="btn btn-sm btn-default" onclick="cancel()">取消</button>
            </div>
        </div>
    </div>

    <script src="{% static 'xadmin/js/jquery-2.1.1.min.js' %}"></script>
    <script src="{% static 'xadmin/ueditor/ueditor.config.js'%}"></script>
    <script src="{% static 'xadmin/ueditor/ueditor.all.js'%}"></script>
    <script src="{% static 'xadmin/layui/layui.all.js'%}"></script>
    <script src="{% static 'xadmin/js/plugins/toastr/toastr.min.js'%}"></script>
    <script src="{% static 'xadmin/js/myjs/toastr_customer.js'%}"></script>
    <script src="{% static 'xadmin/js/plugins/iCheck/icheck.min.js' %}"></script>

    <script>
        //复选框初始化
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green dcheckbox',
            radioClass: 'iradio_square-green',
        });

        function article_add_group(){
            var id_list = [];
            $('.i-checks').each(function(){
                if($(this).get(0).checked){
                    id_list.push($(this).val());
                }
            });
            var gids = id_list.join(',');
            var articleid = '{{ articleid }}';
            $.ajax({
                url: '{% url 'articleaddgroups' %}?siteid={{ siteid }}',
                type: 'post',
                dataType: 'json',
                data: {'gids': gids, 'articleid': articleid, 'csrfmiddlewaretoken': '{{ csrf_token }}'},
                success: function(bk){
                    if(bk.status == '200'){
                        layer.alert(bk.msg, function(){
                            parent.window.location.reload();
                        });
                    }
                    else{
                        layer.alert(bk.msg, {icon: 3});
                    }
                }
            })
        }

        function cancel(){
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index);
        }

    </script>
</body>

</html>